<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="questao" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{questaoHome.managed ? 'Editar' : 'Cadastro de'} Questão</f:facet>

			<s:div styleClass="tableControl" rendered="#{empty from}">
        		<s:link view="/resources/QuestaoList.xhtml"
		                    id="list"
		           propagation="none">
		            <h:graphicImage url="/img/list.png"/>
		            #{' '}
		            <h:outputLabel value="Listagem"/>
		        </s:link>
		    </s:div>

            <s:decorate id="questaoField" template="/layout/edit.xhtml">
                <ui:define name="label">Enunciado</ui:define>
                <h:inputTextarea id="questao"
                               cols="80"
                               rows="3"
                              value="#{questaoHome.instance.questao}"
                           required="true"/>
            </s:decorate>
			
			
            <s:decorate id="tipoQuestaoField" template="/layout/edit.xhtml">
                <ui:define name="label">Tipo da Questão</ui:define>
                <h:selectOneRadio id="tipoQuestao" value="#{questaoHome.instance.tipoQuestao}" styleClass="radio" required="true">
                    <f:selectItem itemLabel="Objetiva" itemValue="Objetiva"/>
                    <f:selectItem itemLabel="Verdadeiro ou Falso" itemValue="VerdadeiroFalso"/>
                </h:selectOneRadio>
            </s:decorate>

            <div style="clear:both">
                <span class="required">*</span>
                campos obrigatórios
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Salvar"
                         action="#{questaoHome.persist}"
                       disabled="#{!questaoHome.wired}"
                       rendered="#{!questaoHome.managed}"/>

            <h:commandButton id="update"
                          value="Salvar"
                         action="#{questaoHome.update}"
                       rendered="#{questaoHome.managed}"/>

            <h:commandButton id="delete"
                          value="Deletar"
                         action="#{questaoHome.remove}"
                      immediate="true"
                       rendered="#{questaoHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancelar"
             propagation="end"
                    view="/resources/Questao.xhtml"
                rendered="#{questaoHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancelar"
             propagation="end"
                    view="/resources/#{empty questaoFrom ? 'QuestaoList' : questaoFrom}.xhtml"
                rendered="#{!questaoHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Questionário">
    <div class="association" id="questionarioParent">

        <h:outputText value="Não existe Questionário atrelado a esta Questão."
                   rendered="#{questaoHome.instance.questionario == null}"/>

        <rich:dataTable var="_questionario"
                   value="#{questaoHome.instance.questionario}"
                rendered="#{questaoHome.instance.questionario != null}"
              rowClasses="odd,even"
                      id="questionarioTable">
            <h:column>
                <f:facet name="header">Nome</f:facet>
                <h:outputText value="#{_questionario.nome}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Nível</f:facet>
                <h:outputText value="#{_questionario.nivel}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Cliques</f:facet>
                <h:outputText value="#{_questionario.cliques}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Data de Cadastro</f:facet>
                <h:outputText value="#{_questionario.dataCadastro.time}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Usuário</f:facet>
                <h:outputText value="#{_questionario.usuario.nome}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{questaoHome.instance.questionario != null ? 'changeParent' : 'selectParent'}" value="#{questaoHome.instance.questionario != null ? 'Trocar' : 'Selecionar'} questionario"
                       view="/resources/QuestionarioList.xhtml">
                <f:param name="from" value="QuestaoEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Resposta">
        <h:form styleClass="association" id="respostaChildren">

            <h:outputText value="Não existe Resposta cadastrada."
                       rendered="#{empty questaoHome.resposta}"/>

            <rich:dataTable value="#{questaoHome.resposta}"
                           var="_resposta"
                      rendered="#{not empty questaoHome.resposta}"
                    rowClasses="odd,even"
                            id="respostaTable">
                <rich:column sortBy="#{_resposta.resposta}">
                    <f:facet name="header">Resposta</f:facet>
                    <h:outputText value="#{_resposta.resposta}"/>
                </rich:column>
                <rich:column sortBy="#{_resposta.cliques}">
                    <f:facet name="header">Cliques</f:facet>
                    <h:outputText value="#{_resposta.cliques}"/>
                </rich:column>
                <rich:column sortBy="#{_resposta.correta}">
                    <f:facet name="header">Correta</f:facet>
                    <h:outputText value="#{_resposta.correta}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{questaoHome.managed}" id="resposta">
        <div class="actionButtons">
            <s:button id="addresposta"
                   value="Cadastrar Resposta"
                    view="/resources/RespostaEdit.xhtml"
             propagation="none">
                 <f:param name="questaoId"
                         value="#{questaoHome.instance.id}"/>
                 <f:param name="respostaFrom" value="Questao"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
